package com.compass.mobile.doctor

import LogUtil
import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.multidex.MultiDexApplication
import com.compass.mobile.framework.helper.CompassAppHelper
import com.compass.mobile.framework.ifly.IFlyHelper
import com.github.mikephil.charting.utils.Utils

class MyApplication : MultiDexApplication() ,Application.ActivityLifecycleCallbacks{
    override fun onCreate() {
        super.onCreate()
        CompassAppHelper.init(this,true)
        Utils.init(this)
        registerActivityLifecycleCallbacks(this)


    }

//    override fun onTerminate() {
//        super.onTerminate()
//    }

    private var activityCount : Int = 0

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
    }

    override fun onActivityStarted(activity: Activity) {
    }

    override fun onActivityResumed(activity: Activity) {
        activityCount++
    }

    override fun onActivityPaused(activity: Activity) {
    }

    override fun onActivityStopped(activity: Activity) {
        activityCount--
        LogUtil.d("activity count ${activityCount}")
        if(activityCount == 0){
            CompassAppHelper.release()
        }
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
    }

    override fun onActivityDestroyed(activity: Activity) {
    }
}